<%@ page language="java" contentType="text/html; charset=UTF-8"
		 pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<title>配置系统</title>
	<jsp:include page="common/common_head.jsp"></jsp:include>

	<link rel="stylesheet" href="/codemirror-4.10/lib/codemirror.css">
	<script src="/codemirror-4.10/lib/codemirror.js"></script>
	<script src="/codemirror-4.10/mode/sql/sql.js"></script>

	<link rel="stylesheet" href="/codemirror-4.10/addon/hint/show-hint.css" />
	<script src="/codemirror-4.10/addon/hint/show-hint.js"></script>
	<script src="/codemirror-4.10/addon/hint/sql-hint.js"></script>
	<style type="text/css">
		body {line-height: 1}
		th {text-decoration: "auto"}
	</style>
</head>
<body  data-spy="scroll" data-target=".navbar">



<jsp:include page="common/common_banner_app.jsp"></jsp:include>
<div style="height:30px"></div>
<div class="container">

	<table class="table  table-striped table-bordered table-hover " id = "showTable">

		<thead>
			<tr>
				<th>序号</th>
				<th>版本</th>
				<th>说明</th>
				<th>添加时间</th>
				<th>操作</th>

			</tr>
		</thead>
		<tbody>
		<c:forEach items="${versions}" var="c" varStatus="v">
			<tr>
				<td>${v.index + 1}</td>
				<td>${c.version}</td>
				<td>${c.comment}</td>
				<td>${c.insert_time}</td>
				<td>
					<a class="btn btn-primary" href="/conf/versionDetail.html?id=${c.id}">查看</a>
					<a class="btn btn-danger" href="/conf/versionRollback.html?id=${c.id}">回滚</a>
				</td>
			</tr>
		</c:forEach>

		</tbody>

	</table>



	<jsp:include page="common/common_js.jsp"></jsp:include>



	<script>



		var editor = null

		$(document).ready(function(){
			editor = CodeMirror.fromTextArea(document.getElementById("sql"), {
				mode: "text/x-mysql",
				indentWithTabs: true,
				smartIndent: true,
				lineNumbers: true,
				matchBrackets : true,
				autofocus: true,
				extraKeys: {"Ctrl-.": "autocomplete", "Ctrl-Enter": function(){search()}},
				hintOptions: {tables: {
					users: {name: null, score: null, birthDate: null},
					countries: {name: null, population: null, size: null}
				}}
			});

		})

		function search(){

			$("#submitBtn").addClass("disabled").val("查询中...")


			$.ajax({
				url: "common/sql.html",
				type: "POST",
				data: {sql: editor.doc.getValue()},
				dataType: "json",
				success: function(r){

					var head = $("#showTable thead")

					head.empty()
					var headArr = []
					headArr.push("<tr><th>序号</th>")
					$.each(r.head,function(i,n){

						headArr.push("<th>" + n +"</th>")

					})
					headArr.push("</tr>")

					head.append(headArr.join(""))


					var data = $("#showTable tbody")

					data.empty()
					var dataArr = []
					$.each(r.dataList,function(i,n){


						dataArr.push("<tr>")


						dataArr.push("<td>" + (i + 1) + "</td>")
						$.each(n, function(x,y){

							dataArr.push("<td>" + y + "</td>")
						});
						dataArr.push("</tr>")

					})

					data.append(dataArr.join(""))

				},
				complete: function(){
					$("#submitBtn").removeClass("disabled").val("查询")

				}
			})
		}
	</script>
</body>
</html>